import React from 'react';
import { View } from '@tarojs/components';
import utils from '@/utils/index';
import './index.scss';

const SearchHistory = ({ className = '', handleHistory }) => {
  let searchHistory = utils.getLocalStorage('searchHistory');
  return (
    <View className={'SearchHistory ' + className}>
      <View className="title">搜索历史</View>
      <View className="list">
        {searchHistory &&
          searchHistory?.length > 0 &&
          searchHistory.map((item) => {
            return (
              <View
                className={'item' + (item.length > 0 ? '' : 'hidden')}
                onClick={() => handleHistory(item)}
                key={item}
              >
                {item}
              </View>
            );
          })}
      </View>
    </View>
  );
};

export default SearchHistory;
